<template>
  <div style="height: 95%;">
    <el-table
        :data="showTable"
        style="width: 100%"
        height=100%
        v-loading="loading"
        element-loading-text="数据正在加载中..."
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
    	>

        <el-table-column
          label="结项名称"
          align=center>
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.phaseName }}</span>
          </template>
        </el-table-column>
    	<el-table-column
    	  label="检查开始日期"
    	  align=center
    	 >
    	  <template slot-scope="scope">
    	    <i class="el-icon-time"></i>
    	    <span style="margin-left: 10px" v-if="scope.row.status==9">{{ scope.row.phaseSchoolFirstStart }}</span>
          <span style="margin-left: 10px" v-if="scope.row.status==11">{{ scope.row.phaseSchoolSecondStart }}</span>
    	  </template>
    	</el-table-column>
    	<el-table-column
    	  label="检查结束日期"
    	  align=center
    	  >
    	  <template slot-scope="scope">
    	    <i class="el-icon-time"></i>
    	    <span style="margin-left: 10px" v-if="scope.row.status==9">{{ scope.row.phaseSchoolFirstEnd }}</span>
          <span style="margin-left: 10px" v-if="scope.row.status==11">{{ scope.row.phaseSchoolSecondEnd }}</span>
    	  </template>
    	</el-table-column>
    	</el-table-column>
        <el-table-column
          align=center
          label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              @click="enterBatch(scope.$index, scope.row)">开始检查</el-button>
          </template>
        </el-table-column>
      </el-table>
    <div class="resource-page">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5,10, 15]"
        :page-size="pagesize"
        :pager-count="7"
        layout=" prev, pager, next,sizes, jumper"
        :total="batchTableData.length"
      >
      </el-pagination>
    </div>
  </div>

</template>

<script>
	export default {
		mounted() {
      this.teacherinfo = this.$store.state.info
			this.getAllData()
			this.getNowDate()

      console.log(this.$store.state.info)
		},
	    data() {
	      return {
      pagesize:5,
      currentPage: 1,
      teacherinfo:'',
      //batch表数据
      batchTableData:[],
      //yyyy-mm-dd型日期
      nowDate:'',
      //加载状态
      loading:true
	      }
	    },
      computed:{
        //showTable计算属性通过slice方法计算表格当前应显示的数据
          showTable() {
            return this.batchTableData.slice(
              (this.currentPage - 1) * this.pagesize,
              this.currentPage * this.pagesize
            );
          },
        },
	    methods: {
        handleSizeChange(psize) {
          this.pagesize = psize;
        },
        handleCurrentChange(currentPage) {
          this.currentPage = currentPage;
        },
	      enterBatch(index, row) {
          console.log(index, row);
          if(row.status==9){
            this.$router.push({path:'/closingSchAudit',query:{phaseId:row.phaseId}})
          }
          if(row.status==11){
            this.$router.push({path:'/closingSecSchAudit',query:{phaseId:row.phaseId}})
          }
	      },
		  //获得数据Axios
		  getAllData(){
			  this.$api.phase.getAllPhase({})
			  .then((response)=>{
				  console.log(response)
				  this.batchTableData=response.data.data.filter((item)=>{
					return  new Date(this.nowDate) >=  Date.parse(item.phaseSchoolFirstStart)
					&& new Date(this.nowDate) <= Date.parse(item.phaseSchoolFirstEnd) && item.status==9 &&item.type==3 ||
          new Date(this.nowDate) >=  Date.parse(item.phaseSchoolSecondStart)
          && new Date(this.nowDate) <= Date.parse(item.phaseSchoolSecondEnd) && item.status==11 &&item.type==3
					console.log(this.batchTableData)
				  })
				  this.loading=false
			  })
		  }
		  ,
		  //得到当前日期
		  getNowDate(){
		    var nowDate = new Date();
		    var year = nowDate.getFullYear();
		    var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1;
		    var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
		     .getDate();
		    var dateStr = year + "-" + month + "-" + day;
		    this.nowDate=dateStr
		    console.log("现在日期："+this.nowDate)
		  },
	    }
	  }
</script>

<style scoped>

</style>
